package security.IntrusionDetection.IPInstrusion;

import java.io.FileNotFoundException;
import java.util.Scanner;

import security.Authentication.Base.AuthenticationRequest;
import security.IntrusionDetection.Base.Email;
import security.IntrusionDetection.Base.IntrusionDetection;

/**
 * Class will detect an unusual ip connection pattern, based on previous logged in ip's.
 * 
 * @author Danut
 *
 */
public class IPIntrusion extends IntrusionDetection{

	private Email em;
	
	public IPIntrusion(Email em)
	{
		this.em=em;
	}
	
	public Email getEmail(){return em;}
	
	@Override
	public boolean isPossibleIntrusion(AuthenticationRequest auth) {
		Scanner scan = null;
		boolean flag=false;
		try {
			scan = new Scanner(log);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		while(scan.hasNext())
		{
			String str = scan.next();
			if(str.equalsIgnoreCase(auth.getAddress().getHostAddress()))
				flag=true;
		}
		if(!flag){em.sendEmail();em.setEmailSentStatus(true);}
		return false;
	}
}
